package cn.tramy.pinxian.wind.command.annotation

import cn.tramy.pinxian.wind.handler.registry.HandlerRegistry
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.config.BeanPostProcessor
import org.springframework.core.annotation.AnnotationUtils


class CommandHandlerBeanPostProcessor : BeanPostProcessor {
    @Autowired
    private lateinit var handlerRegistry: HandlerRegistry

    override fun postProcessAfterInitialization(bean: Any, beanName: String): Any {
        if (AnnotationUtils.findAnnotation(bean.javaClass, CommandHandlerAware::class.java) != null) {
            this.handlerRegistry.registerHandler(bean, CommandHandler::class.java, CommandHandler::class.java.name)
        }
        return super.postProcessAfterInitialization(bean, beanName)
    }
}




